package cn.webrx;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class Stream6 {
    public static void main(String[] args) {
        //建立对象集合
        List<Book> books = new ArrayList<>(List.of(
                new Book(1, "《java基础入门》", "李四", 38),
                new Book(20, "《html基础》", "王四", 28),
                new Book(15, "《企业java项目初步》", "赵四", 18),
                new Book(13, "《mysql数据库技术》", "张四", 88),
                new Book(33, "《mysql》", "张四", 88),
                new Book(9, "《数据库视频》", "李四", 55)));

        //books.stream().parallel().forEach(System.out::println);

        //判断所有书籍是不是价格都超过20元
        //System.out.println(books.stream().allMatch(e -> e.getPrice() > 20));


        //System.out.println(books.stream().anyMatch(e->e.getPrice()>50));

        //System.out.println(books.stream().filter(e->e.getPrice()>50).count());

        //System.out.println(books.stream().filter(e->e.getPrice()>50).findFirst().get());

        //System.out.println(books.stream().filter(e->e.getPrice()>50).findAny().get());

        //Stream<Book> sss = books.stream().parallel();
        //Stream<Integer> sss = Stream.of(1,2,3,4,5,6,7).parallel();
        //System.out.println(sss.findAny().get());

        Optional<Book> first = books.stream().filter(e -> e.getName().contains("jaava")).parallel().findAny();

        //System.out.println(first.orElse(null));

        if(first.isPresent()){
            System.out.println(first.get());
        }
    }
}
